﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fulcrum.UnitTests
{
    [TestClass]
    public class ValueConverterTests
    {
        [TestMethod]
        public void TestValidInt()
        {
            var result = ValueConverter.ConvertStringToObject("123123", typeof(int));

            Assert.AreEqual(123123, result);
        }

        [TestMethod]
        public void TestValidString()
        {
            var result = ValueConverter.ConvertStringToObject("a string", typeof(string));

            Assert.AreEqual("a string", result);
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidCastException))]
        public void TestNull()
        {
            var result = ValueConverter.ConvertStringToObject(null, typeof(int));

            Assert.AreEqual("blah", result);
        }

        [TestMethod]
        [ExpectedException(typeof(FormatException))]
        public void TestEmptyInt()
        {
            var result = ValueConverter.ConvertStringToObject(String.Empty, typeof(int));

            Assert.AreEqual("blah", result);
        }

        [TestMethod]
        public void TestEmptyString()
        {
            var result = ValueConverter.ConvertStringToObject(String.Empty, typeof(string));

            Assert.AreEqual("", result);
        }

        [TestMethod]
        public void TestBoolTrue()
        {
            var result = ValueConverter.ConvertStringToObject("trUe", typeof(bool));

            Assert.AreEqual(true, result);
        }

        [TestMethod]
        public void TestBoolFalse()
        {
            var result = ValueConverter.ConvertStringToObject("faLse", typeof(bool));

            Assert.AreEqual(false, result);
        }

        [TestMethod]
        [ExpectedException(typeof(FormatException))]
        public void TestBoolInvalid()
        {
            var result = ValueConverter.ConvertStringToObject("notset", typeof(bool));

            Assert.AreEqual("blah", result);
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidCastException))]
        public void TestEnumValid()
        {
            var result = ValueConverter.ConvertStringToObject("Create", typeof(FileMode));

            Assert.AreEqual("blah", result);
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidCastException))]
        public void TestEnumInvalid()
        {
            var result = ValueConverter.ConvertStringToObject("notavalue", typeof(FileMode));

            Assert.AreEqual("blah", result);
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidCastException))]
        public void TestEnumNumber()
        {
            var result = ValueConverter.ConvertStringToObject("2", typeof(FileMode));

            Assert.AreEqual("blah", result);
        }

    }
}
